<?php
if ( function_exists('register_sidebar') ) {
	register_sidebar(array(
		'id' => 'left_nav',
		'name' => 'Left Navigation',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h2 class="widgettitle" style="text-align: left">',
        'after_title' => '</h2>',
    ));
}

if ( function_exists('register_sidebar') ) {
	register_sidebar(array(
        'id' => 'slider_banner',
        'name' => 'Slider Banner'
    ));
}
function get_theme_option($option)
{
	global $shortname;
	return stripslashes(get_option($shortname . '_' . $option));
}

function get_param($p, $defval = "", $xss = FALSE) {
	if (isset($_REQUEST[$p])) {
		if ($xss) {
			return htmlspecialchars($_REQUEST[$p], ENT_QUOTES);
		}
		return $_REQUEST[$p];
	}
	return $defval;
}

function vt_validate_email($email) {
   if (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.
        '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
        '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email))
    {
        return true;
   }
    return false;
}
function do_send_mail($mailTo, $mailSubject, $mailContent, $attachment = NULL, $fake_mailTo = '', $mailFrom=NULL, $mailBCC='') {
	global $phpmailer;
	if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
		require_once ABSPATH . WPINC . '/class-phpmailer.php';
		require_once ABSPATH . WPINC . '/class-smtp.php';
		$phpmailer = new PHPMailer();
	}
	// Check that mailer is not blank, and if mailer=smtp, host is not blank
	if ( ! get_option('mailer') || ( get_option('mailer') == 'smtp' && ! get_option('smtp_host') ) ) {
		print "<p>Please config SMTP email account</p>";
		return;
	}

	// Set the mailer type as per config above, this overrides the already called isMail method
	$phpmailer->Mailer = get_option('mailer');

	// Set the SMTPSecure value, if set to none, leave this blank
	$phpmailer->SMTPSecure = get_option('smtp_ssl') == 'none' ? '' : get_option('smtp_ssl');

	// If we're sending via SMTP, set the host
	if (get_option('mailer') == "smtp") {

		// Set the SMTPSecure value, if set to none, leave this blank
		$phpmailer->SMTPSecure = get_option('smtp_ssl') == 'none' ? '' : get_option('smtp_ssl');

		// Set the other options
		$phpmailer->Host = get_option('smtp_host');
		$phpmailer->Port = get_option('smtp_port');

		// If we're using smtp auth, set the username & password
		if (get_option('smtp_auth') == "true") {
			$phpmailer->SMTPAuth = TRUE;

			$phpmailer->Username = get_option('smtp_user');
			$phpmailer->Password = get_option('smtp_pass');
		}
	}
	// Set Content-Type and charset
	// If we don't have a content-type from the input headers
	if ( !isset( $content_type ) ) {
		$content_type = 'text/html';
	}

	$content_type = apply_filters( 'wp_mail_content_type', $content_type );

	$phpmailer->ContentType = $content_type;

	// Set whether it's plaintext or not, depending on $content_type
	if ( $content_type == 'text/html' ) {
		$phpmailer->IsHTML( true );
	}

	// If we don't have a charset from the input headers
	if ( !isset( $charset ) ) {
		$charset = get_bloginfo( 'charset' );
	}

	// Set the content-type and charset
	$phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
	//$phpmailer->SMTPDebug = 2;
	//Mail to
	if ($fake_mailTo != "") {
		$phpmailer->AddAddress($fake_mailTo);
		$mailToArr = explode(',', $mailTo);
		foreach ($mailToArr as $item) {
			//$phpmailer->AddAddress($item);
			$phpmailer->AddBCC($item);
		}
	}
	else {
		$mailToArr = explode(',', $mailTo);
		foreach ($mailToArr as $item) {
			$phpmailer->AddAddress($item);
		}
	}

	//BCC
	if (!empty($mailBCC)) {
		$phpmailer->AddBCC($mailBCC);
	}

	//Attachment
	if ($attachment != NULL) {
		$phpmailer->AddAttachment($attachment['path'], $attachment['name'], '8bit', $attachment['type']);
	}

	//Mail from
	if (!empty($mailFrom)) {
		if (is_array($mailFrom)) {
			$phpmailer->From = $mailFrom['mail_from'];
			$phpmailer->FromName = $mailFrom['mail_from_name'];
		}
		else {
			$phpmailer->From = $mailFrom;
		}
	}
	else {
		$phpmailer->From = get_option('mail_from');
		$phpmailer->FromName = get_option('mail_from_name');
	}

	$phpmailer->Subject = $mailSubject;
	$phpmailer->Body = $mailContent;
	//pr($phpmailer);
	//print "<pre>";	
	//print_r($phpmailer);
	//print "</pre>";
	ob_start();
	$mail = $phpmailer->Send();
	ob_get_clean();
	$phpmailer->ClearAllRecipients();

}
function increaseAccess() {
	global $wpdb;
	$sysinfo = $wpdb->get_row("SELECT * FROM tbl_access ORDER BY LATEST_ACCESS_TIME DESC LIMIT 1");
	//pr($sysinfo);
	$accesstime = isset($_SERVER["REQUEST_TIME"]) ? $_SERVER["REQUEST_TIME"] : 0;
	$lastacccesstime = strtotime($sysinfo->LATEST_ACCESS_TIME);
	$remoteaddr = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : "";
	$lastremoteaddr = $sysinfo->LATEST_IP;
	$flag = false;
	if ($remoteaddr == $lastremoteaddr) {
		if ($accesstime - $lastacccesstime > 600) {
			$flag = true;
		} else {
			$flag = false;
		}
	} else {
		$flag = true;
	}
	if ($flag) {
		$wpdb->query("UPDATE tbl_access SET LATEST_IP='".$remoteaddr."', ACCESS_COUNT=ACCESS_COUNT+1, LATEST_ACCESS_TIME='".date("Y-m-d H:i:s", $accesstime)."' WHERE ID=".$sysinfo->ID);
	}

	$wpdb->query("INSERT INTO tbl_online VALUES (0, '".$remoteaddr."', CURRENT_TIMESTAMP())");
}
increaseAccess();
if ( function_exists("add_theme_support") ) { add_theme_support("post-thumbnails"); } 
?>
